﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SZSLSystem.Web.UI;

namespace SZSLSystem.Web.Admin.DataDictionary
{
    public partial class List : ManagePage
    {
        #region 全局变量

        /// <summary>
        /// 总条数
        /// </summary>
        public int pcount;
        /// <summary>
        /// 当前页
        /// </summary>
        public int page;
        /// <summary>
        /// 设置每页显示的大小
        /// </summary>
        public int pagesize;

        #endregion 

        public readonly SZSLSystem.BLL.DataDictionary bll = new SZSLSystem.BLL.DataDictionary();

        /// <summary>
        /// 页面初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            pagesize = webset.BackgroundPage;
            if (!Page.IsPostBack)
            {
                RptBind();
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void RptBind()
        {
            DataTable dt = bll.GetList(Guid.Parse(DataDictionaryID), false);
            this.rptClassList.DataSource = dt;
            this.rptClassList.DataBind();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rptClassList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            try
            {
                HiddenField txtID = (HiddenField)e.Item.FindControl("txtID");
                HiddenField txtName = (HiddenField)e.Item.FindControl("txtName");
                switch (e.CommandName.ToLower())
                {
                    case "btndel":
                        bll.Delete(Guid.Parse(txtID.Value));
                        //
                        //保存日志
                        //
                        SaveLogs("删除数据字典成功！数据字典名称：" + txtName, 0);

                        JscriptPrint("删除数据字典成功啦！", "List.aspx", "Success");
                        break;
                }
            }
            catch (Exception err)
            {
                //
                //异常日志写入
                //
                SaveLogs(err.ToString(), 1);

                JscriptMsg(350, 230, "错误提示", "<b>出现错误了！</b>删除数据字典失败啦！", "List.aspx", "Error");
            }
        }

        /// <summary>
        /// 美化列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptClassList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal LitFirst = (Literal)e.Item.FindControl("LitFirst");
                HiddenField txtClassLayer = (HiddenField)e.Item.FindControl("txtClassLayer");
                string LitStyle = "<span style=width:{0}px;text-align:right;display:inline-block;>{1}{2}</span>";
                string LitImg1 = "<img src=../images/folder_open.gif align=absmiddle />";
                string LitImg2 = "<img src=../images/t.gif align=absmiddle />";

                int classLayer = Convert.ToInt32(txtClassLayer.Value);
                if (classLayer == 1)
                {
                    LitFirst.Text = LitImg1;
                }
                else
                {
                    LitFirst.Text = string.Format(LitStyle, classLayer * 18, LitImg2, LitImg1);
                }
            }
        }
    }
}
